let rec listRemove liste i = match liste,i with
    e::l,0-> l
   | [],i -> failwith "index out of bounds"
   | e::l,i  -> e::(listRemove l (i-1))

class notebook hbox width height str =
object(this)

val mutable _tabLabel = Obj.magic None

val _tabBox = GPack.hbox ()

method private addLabel =
    let label = GMisc.label ~text:str ~packing:_tabBox#add () in 
  label#misc#set_tooltip_text str;
    label
    
method private initLabel = _tabLabel <- this#addLabel

val _hbox = hbox


val mutable _nbTab = 0
val mutable _listTabLabel = []
val mutable _scroll = Obj.magic None 
val mutable _noteBook = Obj.magic None

val mutable _tab =
  GPack.hbox
    ~homogeneous:false
    ~spacing:4
    ~border_width:4 ()

method private addScroll =
    let scroll= GBin.scrolled_window
    ~hpolicy:`AUTOMATIC
    ~vpolicy:`AUTOMATIC
    ~shadow_type:`ETCHED_IN
    ~packing:_tab#add () in
        scroll

method private initScroll = _scroll <- this#addScroll

method private addNotebook =
let noteBook = GPack.notebook
  ~homogeneous_tabs:true
  ~show_border:true
  ~show_tabs:true
  ~border_width:4
  ~width
  ~height
  ~packing:_hbox#add () in
    this#initScroll;
    this#initLabel;
  begin
      if(str = "Welcome") then(
   let img = GMisc.image ~icon_size:`SMALL_TOOLBAR ~stock:`CLOSE () in 
          let btn_tab = GButton.button  ~relief:`NONE ~packing:_tabBox#pack () in
            btn_tab#set_focus_on_click false;
            btn_tab#set_image img#coerce;
 ignore(btn_tab#connect#clicked ~callback:(fun () -> _tab#misc#hide ())))
  end;

      let _ =  noteBook#insert_page
 ~tab_label:_tabBox#coerce _tab#coerce in 
    let _ = _listTabLabel <- _listTabLabel@[_tabLabel] in 
    noteBook

method getScroll = _scroll
method getNbTab = _nbTab
method getListTabLabel = _listTabLabel

method goto_page n = _noteBook#goto_page n 
method current_page = _noteBook#current_page
method remove_page int = _noteBook#remove_page int
method event = _noteBook#event
method initNoteBook = _noteBook <- this#addNotebook

method createNewOnglet str =
    let hbox = GPack.hbox () in
    let vtab = GPack.vbox 
        ~homogeneous:false 
        ~spacing:4
        ~border_width:4 () in
    let tab = GMisc.label ~text:(if(str = "Info") 
			        then "Info" 
				else(str^(string_of_int(_nbTab+1))))
                          ~packing:hbox#add () in  
    tab#misc#set_tooltip_text str;
    begin
        if(str <> "Info") then(
     let img = GMisc.image ~icon_size:`SMALL_TOOLBAR ~stock:`CLOSE () in 
          let btn_tab = GButton.button  ~relief:`NONE ~packing:hbox#pack () in
            btn_tab#set_focus_on_click false;
            btn_tab#set_image img#coerce ;
 ignore(btn_tab#connect#clicked ~callback:(fun () -> vtab#misc#hide ())))
    end;   
 let _ = _listTabLabel <- _listTabLabel@(tab::[]) in
   let _ = _noteBook#insert_page
        ~tab_label:hbox#coerce vtab#coerce in
    let scroll = GBin.scrolled_window
        ~hpolicy:`AUTOMATIC
        ~vpolicy:`AUTOMATIC
        ~shadow_type:`ETCHED_IN
        ~packing:vtab#add () in
   _nbTab <- _nbTab + 1;
      _noteBook#goto_page _nbTab;
    scroll

method removeCurrentTab = 
    let current = _noteBook#current_page in
    let _ = _noteBook#remove_page current in
    _listTabLabel <- (listRemove _listTabLabel current);
    _nbTab <- _nbTab - 1
 
end
